﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Windows.Media.Imaging;
using System.ComponentModel;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;


namespace TagPropagator
{
    [Serializable]
    [XmlRootAttribute("node")]
    public class Node : IDisposable
    {
        [XmlElement("Image")]
        public String Image { get; set; }

        //[XmlElement("features")]
        [XmlIgnore]
        public SerializableDictionary<string, Feature> Features { get; set; }

        [XmlElement("tags")]
        public SerializableDictionary<string, double> Tags { get; set; }

        [XmlAttribute("id")]
        public int ID { get; set; }

        [XmlElement("neighbours")]
        public SerializableDictionary<int, double> Neighbours { get; set; }


        [XmlIgnore]
        private Image _image;

        [XmlIgnore]
        public Image ImageFile
        {
            get
            {
                if (_image == null)
                {
                    _image = System.Drawing.Image.FromFile(Image);
                }
                return _image;
            }

            set
            {
                _image = value;
            }
        }
        public Node()
        {
            Features = new SerializableDictionary<string, Feature>();
            Tags = new SerializableDictionary<string, double>();
            Neighbours = new SerializableDictionary<int, double>();
        }

        public void Dispose()
        {
            if (_image != null) _image.Dispose();
        }
    }
}
